// author by welong
// zuowl@qq.com
// 2014-09-05  12:48
// PAT basic 1018

//when haven't win once, printf B

#include <stdio.h>

#define POST_A ('B')
#define POST_B ('C')
#define POST_C ('J')

#define WIN1  ('C' - 'J')
#define WIN2  ('J' - 'B')
#define WIN3  ('B' - 'C')

#define LOSE1 ('J' - 'B')
#define LOSE2 ('B' - 'C')
#define LOSE3 ('C' - 'J')

#define WIN_C  4
#define DRAW_C 5
#define LOSE_C 6

char judge(char a, char b)	//a win b, return 1; a draw b, return 0; else return -1
{
	char result = a - b;

	if(result == 0)
		return 0;
	else if(result == WIN1 || result == WIN2 || result == WIN3)
		return 1;
	else
		return -1;
}

int main(int argc, char **argv)
{
	int  i, count;
	int  max_win_a = 0, max_win_b = 0;
	int  pos_max_a = 0, pos_max_b = 0;

	char a[5], b[5], res;				//input array, adapt to input format
	int  aw[25] = {0}, bw[25] = {0};	//store information win,draw,lose and which post win's count
	char post[3] = {POST_A, POST_B, POST_C};

	scanf("%d", &count);

	for(i = 0; i < count; i++)
	{
		scanf("%s%s", a, b);
		res = judge(a[0], b[0]);

		if(res > 0)
		{
			aw[a[0] - 'A']++;
			aw[WIN_C]++;
			bw[LOSE_C]++;
		}
		else if(res == 0)
		{
			aw[DRAW_C]++;
			bw[DRAW_C]++;
		}
		else
		{
			bw[b[0] - 'A']++;
			bw[WIN_C]++;
			aw[LOSE_C]++;
		}
	}

	printf("%d %d %d\n", aw[WIN_C], aw[DRAW_C], aw[LOSE_C]);
	printf("%d %d %d\n", bw[WIN_C], bw[DRAW_C], bw[LOSE_C]);
	
	for(i = 0; i < 3; i++)			//get count & position of max_win of a & b
	{
		count = aw[post[i] - 'A'];  //count restore value as temp
		if(count > max_win_a)
		{
			max_win_a = count;
			pos_max_a = i;
		}

		count = bw[post[i] - 'A'];
		if(count > max_win_b)
		{
			max_win_b = count;
			pos_max_b = i;
		}
	}

	printf("%c %c\n", post[pos_max_a], post[pos_max_b]);
	return 0;
}